import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Index from '../views/Index.vue'
import store from '@/store/index.js'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    redirect: '/index',
    children: [
      {
        path: '/index',
        name: 'Index',
        component: Index,
      },
      {
        path: '/Mavic-series',
        name: 'Mavic-series',
        component: () => import(/* webpackChunkName: "about" */ '../views/shopPage/Mavic-series')
      },
      {
        path: '/0smo-series',
        name: 'Osmo-series',
        component: () => import(/* webpackChunkName: "about" */ '../views/shopPage/Osmo-series')
      },
      {
        path: '/FPV-series',
        name: 'FPV-series',
        component: () => import(/* webpackChunkName: "about" */ '../views/shopPage/FPV-series')
      },
      {
        path: '/Ronin-series',
        name: 'Ronin-series',
        component: () => import(/* webpackChunkName: "about" */ '../views/shopPage/Ronin-series')
      },
    ]
  },
  {
    path: '/product',
    name: 'Product',
    component: () => import(/* webpackChunkName: "about" */ '../views/Product.vue'),
    redirect: '/index',
    children:[
      {
        path: '/product/dji-air-2s',
        name: 'Dji-air-2s',
        component: () => import(/* webpackChunkName: "about" */ '../views/productPage/Dji-air-2s.vue'),
        alias:'/product/676',
        // redirect: '/product/dji-air-2s',
      },
      {
        path: '/product/mini-2',
        name: 'Mini-2',
        component: () => import(/* webpackChunkName: "about" */ '../views/productPage/Mini-2.vue'),
        alias:'/product/752',
      },
      {
        path: '/product/mavic-air-2',
        name: 'Mavic-air-2',
        component: () => import(/* webpackChunkName: "about" */ '../views/productPage/Mavic-air-2.vue'),
        alias:'/product/753',
      },
      {
        path: '/product/mavic-2',
        name: 'mavic-2',
        component: () => import(/* webpackChunkName: "about" */ '../views/productPage/Mavic-2.vue'),
        alias:'/product/754',
      },
      {
        path: '/product/Mavic-mini',
        name: 'Mavic-mini',
        component: () => import(/* webpackChunkName: "about" */ '../views/productPage/Mavic-mini.vue'),
        alias:'/product/755',
      },
      {
        path: '/product/Pocket-2',
        name: 'Pocket-2',
        component: () => import(/* webpackChunkName: "about" */ '../views/productPage/Pocket-2.vue'),
        alias:'/product/678',
      },
    ]
  },
  {
    path: '/confilrm',
    name: 'Confilrm',
    component: () => import(/* webpackChunkName: "about" */ '../views/OrderConfilrm.vue'),
    beforeEnter: (to, from, next) => {
      if ( store.state.token ||sessionStorage.getItem("token")) {
        // 存在正常跳转
        next()
      } else {
        //说明没有登录，就跳转登录页面
        next('/login?redirect='+to.fullPath)
      }
    }
  },
  {
    path: '/test',
    name: 'test',
    component: () => import(/* webpackChunkName: "about" */ '../views/test.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue'),
  },
  {
    path: '/cart',
    name: 'Cart',
    component: () => import(/* webpackChunkName: "about" */ '../views/Cart.vue'),
    beforeEnter: (to, from, next) => {
      if ( store.state.token ||sessionStorage.getItem("token")) {
        // 存在正常跳转
        next()
      } else {
        //说明没有登录，就跳转登录页面
        next('/login?redirect='+to.fullPath)
      }
    }
  },
  {
    path: '/orderlist',
    name: 'OrderList',
    component: () => import(/* webpackChunkName: "about" */ '../views/OrderList.vue'),
    beforeEnter: (to, from, next) => {
      if ( store.state.token ||sessionStorage.getItem("token")) {
        // 存在正常跳转
        next()
      } else {
        //说明没有登录，就跳转登录页面
        next('/login?redirect='+to.fullPath)
      }
    }
  },
  {
    path: '/singleorder/:id',
    name: 'SingleOrder',
    component: () => import(/* webpackChunkName: "about" */ '../views/SingleOrder.vue'),
    beforeEnter: (to, from, next) => {
      if ( store.state.token ||sessionStorage.getItem("token")) {
        // 存在正常跳转
        next()
      } else {
        //说明没有登录，就跳转登录页面
        next('/login?redirect='+to.fullPath)
      }
    }
  },

  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
